package com.jack.leetcode.每日一题;

/*** 
 * @author zhangjie
 * @date 2020/4/27 21:36
 */
public class 搜索旋转排序数组 {

    public static void main(String[] args) {
        int[] nums = {4,5,6,7,0,1,2};
        int target = 0;
        System.out.println(search(nums,0));
    }

    public static int search(int[] nums, int target) {
        int left = 0, right = nums.length - 1;
        while (left < right) {
            int mid = (left + right) / 2;
            if ((nums[mid] < nums[0]) ^ (nums[mid] < target) ^ (target < nums[0])) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        return left == right && nums[left] == target ? left : -1;
    }
}
